﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLogicLayer
{
    public class SuppliersFacade
    {
        InventorySoreDataContext context;
        Supplier supplier;

        public SuppliersFacade()
        {
            context = new InventorySoreDataContext();
        }

        public IQueryable FindAll()
        {
            var suppliers = from sup in context.Suppliers select sup;
            return suppliers;
        }

        public Supplier FindBySupplierID(string supplierID)
        {
            var supp = (from sup in context.Suppliers where sup.SupplierID == supplierID select sup).Single();
            supplier = supp;
            return supplier;
        }
        public string FindContactByID(string supplierID)
        {
            var contactNo = (from sup in context.Suppliers where sup.SupplierID == supplierID select new { sup.PhoneNo }).Single();
            return contactNo.PhoneNo;
        }

        public double FindPriceByItemCodeAndSupplierID(string itemCode, string supplierID)
        {
            var price = (from tenderlist in context.TenderLists where tenderlist.ItemCode == itemCode && tenderlist.SupplierID == supplierID select tenderlist.Price).SingleOrDefault();
            return price;
        }
        ////Testing
        //public static void Main(String[] args)
        //{
        //    var res = new Supplier_DBBroker().FindAll();
        //    foreach (Supplier s in res)
        //    {
        //        Console.WriteLine(s.SupplierID+ " "+s.SupplierName);
        //    }

        //    string st1=Console.ReadLine();
        //    var supply = new Supplier_DBBroker().FindBySupplierID(st1);
        //    Console.WriteLine(supply.SupplierID + " " + supply.SupplierName);
        //}
    }
}
